﻿Imports Negocio
Imports DataLayer
Imports Excepciones
Public Class GesTipoActividad

    Public Shared Function Obtener(OID As Integer) As TipoActividad

        Dim ta As New TipoActividad()
        Try
            Dim repository As IRepository = RepositoryFactory.Create()
            repository.Nombre = "TIPOACTIVIDAD_SP"
            repository.AddParameter("@ID", OID)
            Dim dtTipos As DataTable = repository.ExecuteDataTable()

            If dtTipos.Rows.Count = 1 Then
                For Each dr As DataRow In dtTipos.Rows
                    ta.OID = Convert.ToInt32(dr.Item("taID"))
                    ta.Persistencia = EstadoPersistencia.UPDATE
                    ta.Nombre = dr.Item("taNOMBRE").ToString()
                    ta.Descripcion = dr.Item("taDESCRIPCION").ToString()
                    ta.Progreso = Convert.ToBoolean(dr.Item("taPROGRESO"))
                Next
            Else
                Throw New TipoActividadGetException()
            End If
        Catch ex As Exception
            Throw New TipoActividadGetException()
        End Try

        Return ta

    End Function


    Public Shared Function Consultar() As List(Of TipoActividad)

        Dim tipoactividades As New List(Of TipoActividad)
        Try
            Dim repository As IRepository = RepositoryFactory.Create()
            repository.Nombre = "TIPOACTIVIDAD_SP"
            repository.AddParameter("@ID", Nothing)
            Dim dtTarea As DataTable = repository.ExecuteDataTable()

            For Each dr As DataRow In dtTarea.Rows
                Dim ta As New TipoActividad()
                ta.OID = Convert.ToInt32(dr.Item("taID"))
                ta.Persistencia = EstadoPersistencia.UPDATE
                ta.Nombre = dr.Item("taNOMBRE").ToString()
                ta.Descripcion = dr.Item("taDESCRIPCION").ToString()
                ta.Progreso = Convert.ToBoolean(dr.Item("taPROGRESO"))

                tipoactividades.Add(ta)
            Next

        Catch ex As Exception
            Throw New TipoActividadGetException()
        End Try

        Return tipoactividades
    End Function
End Class
